const API_ROOT = process.env.VUE_APP_API_ROOT;
let apiObj = {};
const apiContext = require.context('./', false, /\.js$/);
apiContext.keys().forEach((item) => {
    if (item === './index.js') return;
    let regex = /\.\/(.+?)\./g;
    let apiName = regex.exec(item)[1];
    apiObj[apiName] = apiContext(item);
});
const apiConfig = {
    apiRoot: API_ROOT,
    getAllPath: (path) => API_ROOT + (typeof (path) == 'string' ? path : path.url),
    ...apiObj
};

export default {
    install: function (Vue) {
        Vue.prototype.$api = apiConfig
    }
}
